﻿
@{
    ViewBag.Title = "Notendur";
}

<h2>Notendur</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@section scripts{ <script type="text/javascript" src="~/Javascripts/ListUsers.js"></script> }
<h4>Virkir notendur:</h4>
<table class="listuserstable">
    <thead>
        <tr>
            <th>Nafn:</th>
            <th>Roles:</th>
            <th>Aðgerðir:</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var user in Model.legalUsers)
    {
        <tr>
            <td>
                <div id="@user.UserId">@user.UserName</div>
            </td>
            <td>
                    @if (Roles.IsUserInRole(user.UserName, "Moderators"))
                    { 
                        <text>Moderators</text>
                    }
                    @if (Roles.IsUserInRole(user.UserName, "Administrators"))
                    { 
                        <text>Administrators</text>
                    }
                    @if (!Roles.IsUserInRole(user.UserName, "Administrators") && !Roles.IsUserInRole(user.UserName, "Moderators"))
                    { 
                        <text>Users</text>
                    }
            </td>
            <td>
                @if (!Roles.IsUserInRole(user.UserName, "Administrators"))
                { 
                    
                    if(user.UserName == User.Identity.Name)
                    {
                        if (user.UserName != "admin" && user.UserName != "moderator")
                        {
                            <text><a href="~/Account/DeleteUser/@user.UserId" class="deleteuser">Eyða mér</a>&nbsp;</text>
                        }
                        <text>
                            <a href="~/Account/DisableUser/@user.UserId"  class="disableuser">Gera mig óvirkan</a>&nbsp;
                            <a href="~/Account/MakeUserUser/@user.UserId"  class="makeuseruser">Breyta mér í User</a>
                        </text>
                    }
                    else
                    {
                        if(!Roles.IsUserInRole(user.UserName, "Moderators"))
                        {
                            <text>
                                <a href="~/Account/DeleteUser/@user.UserId"  class="deleteuser">Eyða notanda</a>&nbsp;
                                <a href="~/Account/DisableUser/@user.UserId"  class="disableuser">Gera óvirkan</a>&nbsp;
                                @if(Roles.IsUserInRole(User.Identity.Name, "Administrators"))
                                {
                                    <text><a href="~/Account/MakeUserAdmin/@user.UserId"  class="makeuseradmin">Breyta í Administrator</a>&nbsp;</text>
                                }
                                <a href="~/Account/MakeUserModerator/@user.UserId">Breyta í Moderator</a>
                            </text>
                        }
                        else if (Roles.IsUserInRole(User.Identity.Name, "Moderators"))
                        { 
                                
                        }
                        else
                        {
                            <text>
                                <a href="~/Account/DeleteUser/@user.UserId"  class="deleteuser">Eyða notanda</a>&nbsp;
                                <a href="~/Account/DisableUser/@user.UserId"  class="disableuser">Gera óvirkan</a>&nbsp;
                                @if(Roles.IsUserInRole(User.Identity.Name, "Administrators"))
                                {
                                    <text><a href="~/Account/MakeUserAdmin/@user.UserId"  class="makeuseradmin">Breyta í Administrator</a>&nbsp;</text>
                                }
                                <a href="~/Account/MakeUserUser/@user.UserId">Breyta í User</a>
                            </text>
                        }
                    }
                }
                else
                {
                    if (user.UserName == User.Identity.Name)
                    { 
                        if (user.UserName != "admin" && user.UserName != "moderator")
                        {
                            <text><a href="~/Account/DeleteUser/@user.UserId" class="deleteuser">Eyða mér</a>&nbsp;
                            <a href="~/Account/DisableUser/@user.UserId"  class="disableuser">Gera mig óvirkan</a>&nbsp;
                            <a href="~/Account/MakeUserModerator/@user.UserId">Breyta í Moderator</a>&nbsp;
                            <a href="~/Account/MakeUserUser/@user.UserId"  class="makeuseruser">Breyta mér í User</a></text>
                        }
                    }
                    else if(user.UserName != "admin" && user.UserName != "moderator")
                    {
                        <text><a href="~/Account/DeleteUser/@user.UserId" class="deleteuser">Eyða notanda</a>&nbsp;
                        <a href="~/Account/DisableUser/@user.UserId"  class="disableuser">Gera óvirkan</a>&nbsp;
                        <a href="~/Account/MakeUserModerator/@user.UserId">Breyta í Moderator</a>&nbsp;
                        <a href="~/Account/MakeUserUser/@user.UserId"  class="makeuseruser">Breyta í User</a></text>
                    }
                }
            </td>
        </tr>
    }
    </tbody>
</table>
<h4>Óvirkir notendur:</h4>
<table class="listuserstable">
    <thead>
        <tr>
            <th>Nafn:</th>
            <th>Roles:</th>
            <th>Aðgerðir:</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var user in Model.disabledUsers)
    {
        <tr>
            <td>
                @user.UserName
            </td>
            <td>
                @if (Roles.IsUserInRole(user.UserName, "Moderators"))
                { 
                    <text>Moderators</text>
                }
                @if (Roles.IsUserInRole(user.UserName, "Administrators"))
                { 
                    <text>Administrators</text>
                }
                @if (!Roles.IsUserInRole(user.UserName, "Administrators") && !Roles.IsUserInRole(user.UserName, "Moderators"))
                { 
                    <text>Users</text>
                }
            </td>
            <td>
                <a href="~/Account/ActivateUser/@user.UserId">Gera virkan</a>
            </td>
        </tr>
    }
    </tbody>
</table>

